package com.haohe.wx.util;

import org.springframework.context.ApplicationContext;

/**
 * 
 * @Title Spring工具类
 * @Description TODO
 * @author liming.zhao@haohedata.com
 * @date 2015-7-21 
 * @time 下午3:35:52
 */
public class SpringUtil {

	private static ApplicationContext context;

	public static ApplicationContext getContext() {
		return context;
	}

	public static Object getBean(String beanId) throws Exception {
		Object bean = context.getBean(beanId);
		if (bean == null)
			return null;
		return bean;
	}

	public static <T> T getBean(String beanId, Class<T> clazz) throws Exception {
		T bean = context.getBean(beanId, clazz);
		if (bean == null)
			return null;
		return bean;
	}

	public static void setContext(ApplicationContext ctx) {
		context = ctx;
	}

}